package com.filetransfer.domain;

import java.io.Serializable;

public class FileInfo implements Serializable, Comparable<FileInfo>{

	/**
	 *
	 */
	private static final long serialVersionUID = -975464332064827467L;

	protected String fileName;
	protected long fileSize;
	protected int chunkSize;
	protected int numChunks;

	public int getChunkSize() {
		return chunkSize;
	}



	public void setChunkSize(int chunkSize) {
		this.chunkSize = chunkSize;
	}



	public int getNumChunks() {
		return numChunks;
	}



	public void setNumChunks(int numChunks) {
		this.numChunks = numChunks;
	}



	/**
	 *
	 * @param name
	 * @param size
	 */
	public FileInfo(String name, long size){
		setFileName(name);
		setFileSize(size);
	}



	public void setFileName(String name){
		fileName = name;
	}

	public String getFileName() {
		return fileName;
	}


	public long getFileSize(){
		return fileSize;
	}


	public void setFileSize(long size){
		fileSize = size;
	}


	public boolean equals(Object obj){
		boolean equals = false;
		if(obj instanceof FileInfo){
			FileInfo info = (FileInfo)obj;
			if(info != null && info.getFileName().trim().equalsIgnoreCase(this.fileName.trim())){
				equals = true;
			}
		}
		return equals;
	}
	
	
	public int compareTo(FileInfo obj){
		return obj.getFileName().trim().compareToIgnoreCase(this.fileName.trim());
	}


	public String toString(){
		return " File-Info: " + fileName + " ,size:" + fileSize/1024 + " KB.";
	}

	
	/**
	 * For debugging purposes.
	 * @return
	 */
	public String toStringDetailed(){
		StringBuilder bldr = new StringBuilder();
		
		bldr.append(toString()).append("\n");
		if(chunkSize != 0){
			bldr.append("\tchunk-size:" + chunkSize/1024 + " KB\n");
		}
		if(numChunks != 0){
			bldr.append("\tnum of chunks:" + numChunks+ " \n");
		}
		return bldr.toString();
	}
}
